<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets" >
<ui:composition template="/templates/principal.xhtml" >
<ui:define name="corpo" >
<h:head>
    <title>Manter Processos</title>
</h:head>
<h:body>
<p:growl id="mensagens"  />
<p:panel header="Manter processos" style="text-align: center; height: 35px; padding: 0px; font-size: 16px"/>
<p:layout style="width: auto; height: 1024px;" >
    <h:form id="tabelaProcesso" prependId="false" style="overflow: auto;">
        <h:panelGrid columns="8" cellspacing="2">
            <h:outputLabel value="Filtrar processo:" style="font-weight: bold" />
                <h:selectOneMenu value="#{processoBean.filtroSelecionado}" >
                    <f:selectItem itemValue="-1" itemLabel="Selecione" />
                    <f:selectItem itemValue="1" itemLabel="Ativo" />
                    <f:selectItem itemValue="2" itemLabel="Arquivado" />
                    <f:ajax execute="@this" render="tabelaProcesso" event="change"  />
                </h:selectOneMenu>
            </h:panelGrid>
            <p:dataTable var="processo" value="#{processoBean.listarProcessoPorStatus}" emptyMessage="Não há informações!"
            paginator="true" paginatorPosition="both" rows="15" selectionMode="single" 
            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
            rowsPerPageTemplate="5,15,30" style="overflow: auto;">
            <h:inputHidden value="#{processo.idprocesso}" />
            <p:column headerText="Editar" rendered="#{contextoBean.usuarioLogado.permissao == 'ROLE_ADMINISTRADOR' or contextoBean.usuarioLogado.permissao == 'ROLE_PROTOCOLISTA'}" style="width: 5%" >
                <center>
                    <p:commandLink title="Editar" immediate="true" action="#{processoBean.editar}" oncomplete="editarProcessoDialog.show();" rendered="#{processo.status == 1}" update="editarProcesso, tabelaProcesso, mensagens" >
                        <h:graphicImage library="imagens" name="editar16.png" style="border:0"/>
                        <f:setPropertyActionListener target="#{processoBean.processo}" value="#{processo}"  />
                    </p:commandLink>
                </center>
            </p:column>
            <p:column headerText="Excluir" rendered="#{contextoBean.usuarioLogado.permissao == 'ROLE_ADMINISTRADOR'}" style="width: 5%" >
                <center>
                    <p:commandLink action="#{processoBean.excluir}" update="tabelaProcesso, mensagens" title="Excluir" onclick="if (!confirm('Confirma a exclusão do PAG Nº #{processo.pag}? Essa ação irá excluir todo o histórico vinculado.')) return false; " ajax="false" immediate="true" rendered="#{processo.status == 1}" >
                        <h:graphicImage library="imagens" name="excluir16.png" style="border:0" />
                        <f:setPropertyActionListener target="#{processoBean.processo}" value="#{processo}" />
                    </p:commandLink>
                </center>
            </p:column>
            <p:column headerText="Detalhes" style="width: 5%" >
                <center>
                    <p:commandLink title="Detalhes do processo" oncomplete="detalhesProcessoDialog.show();" update="detalhesProcesso"  >
                        <h:graphicImage library="imagens" name="detalhes_16.png" style="border:0"/>
                        <f:setPropertyActionListener target="#{processoBean.processo}" value="#{processo}"  />
                    </p:commandLink>
                </center>
            </p:column>
            <p:column headerText="PAG" filterBy="#{processo.pag}" >
                <center>
                    <h:outputText value="#{processo.pag}" title="Detalhes do processo" />
                </center>
            </p:column>
            <p:column headerText="PAM" filterBy="#{processo.pam}" >
                <center>
                    <h:outputText value="#{processo.pam}" />
                </center>
            </p:column>
            <p:column headerText="OM solicitante" >
                <center>
                    <h:outputText value="#{processo.unidadeSolicitante}" >
                        <f:converter converterId="ConverteUnidadeMilitarSiglaId"/>
                    </h:outputText>
                </center>
            </p:column>
            <p:column headerText="Setor solicitante" >
                <center>
                    <h:outputText value="#{processo.setorSolicitante}" >
                        <f:converter converterId="ConverteSetorSiglaId"/>
                    </h:outputText>
                </center>
            </p:column>
            <p:column headerText="Objeto" style="width: 18%">
                <center>
                    <h:outputText value="#{processo.objeto}" />
                </center>
            </p:column>
            <p:column headerText="Doc." >
                <center>
                    <p:commandLink ajax="false" immediate="true" onclick="if (!confirm('Confirma baixar o PAG nº #{processo.pag}?')) return false;" rendered="#{processo.arquivo == true}" >
                        <f:setPropertyActionListener target="#{processoBean.processo}" value="#{processo}" />
                        <p:fileDownload value="#{processoBean.arquivoRetornoPAG}" contentDisposition="inline" />
                        <h:graphicImage library="imagens" name="pdf_#{processo.arquivo}.png" style="border:0;" title="Presente"/>
                    </p:commandLink>
                    <p:commandLink disabled="true" rendered="#{processo.arquivo == false}" >
                        <h:graphicImage library="imagens" name="pdf_#{processo.arquivo}.png" style="border:0" title="Ausente" />
                    </p:commandLink>
                </center>
            </p:column>
            <!--
            <p:column headerText="Status" style="width: 8%" >
                <center>
                    <h:outputText value="Ativo" rendered="#{processo.status == 1}" style="color: green;" />
                    <h:outputText value="Arquivado" rendered="#{processo.status == 2}" style="color: red;" />
                </center>
            </p:column>
            -->
            <p:column>
                <center>
                    <p:commandButton value="Volumes" update="tabelaVolumes" image="ui-icon ui-icon-newwin" onclick="volumeDialog.show()" >
                        <f:setPropertyActionListener target="#{volumeProcessoBean.processoSelecionado}" value="#{processo.idprocesso}" />
                        <f:setPropertyActionListener target="#{volumeProcessoBean.status}" value="#{processo.status}" />
                    </p:commandButton>
                </center>
            </p:column> 
            <p:column>
                <center>
                    <p:commandButton value="Anexos"  update="tabelaAnexos" image="ui-icon ui-icon-newwin" onclick="anexoDialog.show()" >
                        <f:setPropertyActionListener target="#{anexoProcessoBean.processoSelecionado}" value="#{processo.idprocesso}" />
                        <f:setPropertyActionListener target="#{anexoProcessoBean.status}" value="#{processo.status}" />
                    </p:commandButton>
                </center>
            </p:column>
            <p:column rendered="#{contextoBean.usuarioLogado.permissao == 'ROLE_ADMINISTRADOR'}" >
            <center>
                <p:commandButton value="Arquivar" immediate="true" image="ui-icon ui-icon-check"  update="motivoArquivamento, tabelaProcesso, mensagens" oncomplete="editarDialog.show()" rendered="#{processo.status == 1}"  style="width: 105px" >
                    <f:setPropertyActionListener target="#{processoBean.processo}" value="#{processo}" />
                </p:commandButton>
                <p:commandButton value="Desarquivar" image="ui-icon ui-icon-cancel" action="#{processoBean.manter}" ajax="true" immediate="true" update="tabelaProcesso, mensagens" onclick="if (!confirm('Confirma desarquivar o processo nº #{processo.pag}?')) return false;" rendered="#{processo.status == 2}" style="width: 105px" >
                    <f:setPropertyActionListener target="#{processoBean.processo}" value="#{processo}" />
                </p:commandButton>
            </center>
            </p:column>
        </p:dataTable>
    </h:form>
    </p:layout>
</h:body>
    
<p:dialog header="Detalhes do processo" widgetVar="detalhesProcessoDialog" resizable="false" modal="true" width="450" showEffect="explode" hideEffect="explode" >  
    <h:form id="detalhesProcesso" prependId="false" >
        <h:inputHidden value="#{processoBean.processo.idprocesso}" />
        <p:fieldset>
        <center>
            <h:graphicImage library="imagens" name="logo.png" width="380" style="border:0" />
            <br />
            <hr />
            <h:outputLabel value="PAG #{processoBean.processo.pag}" style="font-weight: bold; font-size: 14px"/>
        </center>
        <hr />
        <h:panelGrid columns="2" cellspacing="4" cellpadding="2">
            <h:outputLabel value="PAM:" style="font-weight: bold;" />
            <h:outputLabel value="#{processoBean.processo.pam}" />
            <h:outputLabel value="Unidade do PAM:" style="font-weight: bold;" />
            <h:outputLabel value="#{processoBean.processo.unidadeSolicitante}" >
                <f:converter converterId="ConverteUnidadeMilitarSiglaId"/>
            </h:outputLabel>
            <h:outputLabel value="Setor do PAM:" style="font-weight: bold;" />
            <h:outputLabel value="#{processoBean.processo.setorSolicitante}" >
                <f:converter converterId="ConverteSetorSiglaId"/>
            </h:outputLabel>
            <h:outputLabel value="Data do PAG:" style="font-weight: bold;" />
            <h:outputLabel value="#{processoBean.processo.dataProcesso}" >
                <f:convertDateTime dateStyle="medium" locale="pt,BR" timeZone="America/Sao_Paulo" />
            </h:outputLabel>
            <h:outputLabel value="Status" style="font-weight: bold;" />
            <h:outputLabel value="Ativo" rendered="#{processoBean.processo.status == 1}" style="color: green; text-decoration: blink;" />
            <h:outputLabel value="Arquivado" rendered="#{processoBean.processo.status == 2}" style="color: red;" />
            <h:outputLabel value="Objeto:" style="font-weight: bold;" />
            <h:outputLabel value="#{processoBean.processo.objeto}" style="text-align: justify;"/>
            <h:outputLabel value="Cadastrado por:" style="font-weight: bold;" />
            <h:outputLabel value="#{processoBean.processo.cadastradoPor}" style="text-align: justify;"/>
            <h:outputLabel value="Cadastrado em:" style="font-weight: bold;" />
            <h:outputLabel value="#{processoBean.processo.dataCadastramento}" >
                <f:convertDateTime dateStyle="medium" locale="pt,BR" timeZone="America/Sao_Paulo" />
            </h:outputLabel>
            <h:outputLabel value="Motivo arquivamento:" style="font-weight: bold;" rendered="#{!empty processoBean.processo.motivoArquivamento}" />
            <h:outputLabel value="#{processoBean.processo.motivoArquivamento}" style="text-align: justify;" rendered="#{!empty processoBean.processo.motivoArquivamento}" />
        </h:panelGrid>
        </p:fieldset>
        <br />
        <center>
            <p:commandButton oncomplete="detalhesProcessoDialog.hide();" action="detalhesProcessoDialog.hide();" value="Fechar"/>
        </center>
    </h:form>
</p:dialog>

<p:dialog header="Arquivar" widgetVar="editarDialog" resizable="false" modal="true" width="430" showEffect="explode" hideEffect="explode" >  
    <h:form id="motivoArquivamento" prependId="false"  >
        <h:inputHidden value="#{processoBean.processo.idprocesso}" />
        <p:fieldset>
        <center>
            <h:graphicImage library="imagens" name="logo.png" width="380" style="border:0" />
            <br />
            <hr />
            <h:outputLabel value="Processo nº #{processoBean.processo.pag}" style="font-weight: bold; font-size: 14px"/>
        </center>
        <hr />
        <h:outputLabel />
        <h:panelGrid columns="2" >
            <h:outputLabel value="Motivo:" style="font-weight: bold;" />
            <br />
            <h:inputTextarea value="#{processoBean.motivo}" cols="55" rows="8" />
        </h:panelGrid>
        </p:fieldset>
        <br />
        <center>
            <p:commandButton value="Salvar" action="#{processoBean.manter}" update="tabelaProcesso, motivoArquivamento, mensagens" oncomplete="editarDialog.hide();"  image="ui-icon ui-icon-disk"  />
        </center>
    </h:form>
</p:dialog>

<p:dialog header="Editar" widgetVar="editarProcessoDialog" resizable="false" modal="true" width="850" showEffect="explode" hideEffect="explode" >  
    <h:form id="editarProcesso" prependId="false"  >
        <h:inputHidden value="#{processoBean.processo.idprocesso}" />
        <p:fieldset>
        <h:panelGrid columns="3" cellpadding="3" >
            <h:outputLabel value="PAG:" for="pag" />
            <h:inputText id="pag" value="#{processoBean.processo.pag}" required="true" size="16" requiredMessage="Campo PAG obrigatório!" maxlength="255" style="text-transform: uppercase;" disabled="true">
                <p:ajax event="blur" update="pagMessage"  /> 
            </h:inputText>
            <h:outputLabel/>
            <h:outputLabel value="PAM:" for="pam" />
            <h:inputText id="pam" value="#{processoBean.processo.pam}" required="true" size="16" requiredMessage="Campo PAM obrigatório!" maxlength="255" style="text-transform: uppercase;" disabled="true" >
                <p:ajax event="blur" update="pamMessage" /> 
            </h:inputText>
            <h:message id="pamMessage" for="pam" style="color: red; font-size: 11px"/> 
            <h:outputLabel value="Unidade do PAM:" for="unidade" />
            <h:selectOneMenu  id="unidade" value="#{processoBean.processo.unidadeSolicitante}" valueChangeListener="#{setorBean.selecionaSetorPorOM}" required="true" requiredMessage="Campo Unidade obrigatório!" >
                <f:selectItem itemValue="-1" itemLabel="Selecione"  />
                <f:selectItems value="#{unidadeMilitarBean.listarTipos}" var="it" itemValue="#{it.value}" itemLabel="#{it.key}" />
                <f:ajax execute="@this" render="setorP" event="change"  />
                <p:ajax event="blur" update="unidadeMessage"  />
            </h:selectOneMenu>
            <h:message id="unidadeMessage" for="unidade" style="color: red; font-size: 11px" />
            <h:outputLabel value="Setor do PAM: " for="setorP" />
            <h:selectOneMenu id="setorP" value="#{processoBean.processo.setorSolicitante}" immediate="true" required="true" requiredMessage="Campo Setor obrigatório!" >
                <f:selectItem itemValue="-1" itemLabel="Selecione"  />
                <f:selectItems  value="#{setorBean.listarSetorPorOm}" var="item" itemValue="#{item.idsetor}" itemLabel="#{item.descricaoSetor}" />
                <p:ajax event="blur" update="setorMessage"  />
            </h:selectOneMenu>
            <h:message id="setorMessage" for="setorP" style="color: red; font-size: 11px" /> 
            <h:outputLabel value="Data PAG:" for="dataPag" />
            <p:calendar id="dataPag" value="#{processoBean.processo.dataProcesso}" size="10" required="true" showOn="button" validatorMessage="O formato deve ser dd/mm/aaaa" requiredMessage="Campo Data PAG obrigatório!" readOnlyInputText="true" locale="pt,BR" timeZone="America/Sao_Paulo" pattern="dd/MM/yyyy" /> 
            <h:message id="dataPagMessage" for="dataPag" style="color: red; font-size: 11px"/>
            <h:outputLabel value="Arquivo (Somente PDF):" for="arquivo"/>
            <h:inputText id="arquivo" value="#{processoBean.nomeArquivoSelecionado}" disabled="true" size="45" />
            <p:fileUpload label="Selecione..." sizeLimit="" auto="true" width="120" allowTypes="*.pdf" multiple="false" description="pdf" fileUploadListener="#{processoBean.fileUploadAction}" wmode="advanced" update="arquivo"  />
            <h:outputLabel value="Objeto:" for="objeto" />
        </h:panelGrid>
        <h:panelGroup>
            <p:inputTextarea id="objeto" value="#{processoBean.processo.objeto}" immediate="true" required="true" cols="60" rows="10" autoResize="false" requiredMessage="Campo Objeto obrigatório!" style="font-size: 11px;" >
                <p:ajax event="blur" update="objetoMessage"  />
            </p:inputTextarea>
            <h:message id="objetoMessage" for="objeto" style="color: red; font-size: 11px"/> 
        </h:panelGroup>
        <br />
        <h:panelGrid columns="2" cellpadding="3" >
            <h:outputLabel value="Data cadastramento:" />
            <h:outputText  value="#{processoBean.processo.dataCadastramento}" style="font-weight: bold;" rendered="#{processoBean.processo.idprocesso ne null}">
                <f:convertDateTime dateStyle="medium" locale="pt,BR" timeZone="America/Sao_Paulo" />
            </h:outputText>
            <h:outputText  value="#{processoBean.dataAtual}" style="font-weight: bold;" rendered="#{processoBean.processo.idprocesso eq null}" >
                <f:convertDateTime dateStyle="medium" locale="pt,BR" timeZone="America/Sao_Paulo" />
            </h:outputText>
        </h:panelGrid>
        </p:fieldset>
        <br />
        <h:panelGroup>
            <center>
                <p:commandButton action="#{processoBean.salvar}" value="Salvar" update="editarProcesso, tabelaProcesso, mensagens" style="font-size: 11px" image="ui-icon ui-icon-disk" oncomplete="editarProcessoDialog.hide();" />
                <p:commandButton value="Fechar" oncomplete="editarProcessoDialog.hide();" action="editarProcessoDialog.hide();" />
            </center>
        </h:panelGroup>
    </h:form>
</p:dialog>

<p:dialog header="Volumes" widgetVar="volumeDialog" resizable="false" modal="true" width="540" showEffect="explode" hideEffect="explode" position="top">  
    <h:form id="tabelaVolumes" prependId="false" >
        <p:menubar rendered="#{volumeProcessoBean.status == 1}" >
            <p:menuitem value="Incluir" immediate="false" ajax="true" icon="ui-icon ui-icon-plus" action="#{volumeProcessoBean.incluirVolume}" update="tabelaVolumes" />
            <p:menuitem value="Excluir" immediate="false" ajax="true" icon="ui-icon ui-icon-minus" action="#{volumeProcessoBean.excluirVolume}" update="tabelaVolumes, mensagens" rendered="#{volumeProcessoBean.trataBotao}"/>
        </p:menubar>
        <p:dataTable var="volume" value="#{volumeProcessoBean.listarVolumesPorProcesso}" emptyMessage="Não há informações!"
            paginator="true" paginatorPosition="top" rows="15" selectionMode="single"  
            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
            rowsPerPageTemplate="15,30,60" style="overflow: auto;" >
            <h:inputHidden value="#{volume.idprocesso}" />
            <h:inputHidden value="#{volume.idvolume}" />
            <p:columnGroup type="header">  
                <p:row>
                    <p:column colspan="4" headerText="PAG #{volumeProcessoBean.numeroPag}" style="color: black; font-size: 12px" />
                </p:row> 
                <p:row>  
                    <p:column headerText="Volume" /> 
                    <p:column headerText="Cadastrado por" />
                    <p:column headerText="Cadastrado em" /> 
                </p:row> 
            </p:columnGroup>
            <p:column>
                <center>
                    <h:outputText value="#{volume.volume}" />
                </center>
            </p:column>
            <p:column>
                <center>
                    <h:outputText value="#{volume.cadastradoPor}" />
                </center>
            </p:column>
            <p:column>
                <center>
                    <h:outputText value="#{volume.dataCadastramento}" >
                        <f:convertDateTime dateStyle="medium" locale="pt,BR" timeZone="America/Sao_Paulo" />
                    </h:outputText>
                </center>
            </p:column>

        </p:dataTable>
        <br />
        <center>
            <p:commandButton value="Fechar" oncomplete="volumeDialog.hide();" action="volumeDialog.hide();" />
        </center>
    </h:form>
</p:dialog>
<p:dialog header="Anexos" widgetVar="anexoDialog" resizable="false" modal="true" width="540" showEffect="explode" hideEffect="explode" position="top">  
    <h:form id="tabelaAnexos" prependId="false" >
        <p:menubar rendered="#{anexoProcessoBean.status == 1}" >
            <p:menuitem value="Incluir" immediate="false" ajax="true" icon="ui-icon ui-icon-plus" action="#{anexoProcessoBean.incluirAnexo}" update="tabelaAnexos" />
            <p:menuitem value="Excluir" immediate="false" ajax="true" icon="ui-icon ui-icon-minus" action="#{anexoProcessoBean.excluirAnexo}" update="tabelaAnexos, mensagens" rendered="#{anexoProcessoBean.trataBotao}"/>
        </p:menubar>
        <p:dataTable var="anexo" value="#{anexoProcessoBean.listarAnexosPorProcesso}" emptyMessage="Não há informações!"
            paginator="true" paginatorPosition="top" rows="15" selectionMode="single"  
            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
            rowsPerPageTemplate="15,30,60" style="overflow: auto;" >
            <h:inputHidden value="#{anexo.idprocesso}" />
            <h:inputHidden value="#{anexo.idanexo}" />
            <p:columnGroup type="header">  
                <p:row>
                    <p:column colspan="4" headerText="PAG #{anexoProcessoBean.numeroPag}" style="color: black; font-size: 12px" />
                </p:row> 
                <p:row>  
                    <p:column headerText="Anexo" /> 
                    <p:column headerText="Cadastrado por" />
                    <p:column headerText="Cadastrado em" /> 
                </p:row> 
            </p:columnGroup>
            <p:column>
                <center>
                    <h:outputText value="#{anexo.anexo}" />
                </center>
            </p:column>
            <p:column>
                <center>
                    <h:outputText value="#{anexo.cadastradoPor}" />
                </center>
            </p:column>
            <p:column>
                <center>
                    <h:outputText value="#{anexo.dataCadastramento}" >
                        <f:convertDateTime dateStyle="medium" locale="pt,BR" timeZone="America/Sao_Paulo" />
                    </h:outputText>
                </center>
            </p:column>

        </p:dataTable>
        <br />
        <center>
            <p:commandButton value="Fechar" oncomplete="anexoDialog.hide();" action="anexoDialog.hide();" />
        </center>
    </h:form>
</p:dialog>
</ui:define>
</ui:composition>
</html>